
/****** Object:  StoredProcedure [dbo].[ws_ins_zetas]    Script Date: 10/19/2013 09:22:25 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

IF EXISTS (SELECT * FROM sys.objects WHERE type = 'P' AND name = 'ws_ins_zetas')
DROP PROCEDURE ws_ins_zetas
GO

CREATE PROCEDURE [dbo].[ws_ins_zetas] 
(		
	@term_id varchar(255), 
	@zetas varchar(255), 
	@kada varchar(255), 
	@gryni varchar(255), 
	@bankas varchar(255),
	@kreditas varchar(255),
	@technologija varchar(255)
)
AS
BEGIN
	DECLARE @nuo datetime
	DECLARE @iki datetime
	
	if day(current_timestamp) < 16
	begin
		SET @nuo = DATEADD(month, DATEDIFF(month, 0, CURRENT_TIMESTAMP), 0) --1
		SET @iki = CAST(CAST(year(CURRENT_TIMESTAMP) as varchar) + '-' + cast(month(CURRENT_TIMESTAMP) as varchar) + '-' + '15 23:59:00'  AS DATETIME)
	end
	else	
	begin
		SET @nuo = CAST(cast(year(CURRENT_TIMESTAMP) as varchar) + '-' + cast(month(CURRENT_TIMESTAMP) as varchar) + '-' + '16 00:00:00'  AS DATETIME)
		SET @iki = DATEADD(d, -1, DATEADD(m, DATEDIFF(m, 0, CURRENT_TIMESTAMP) + 1, 0))	--31
	end


	insert into zetai (id,zetas,NUO,IKI,KADA,[realizacijos suma gryni],[realizacijos suma korteles],[realizacijos suma kreditas],technologija ) 
	values (cast(@term_id as integer),cast(@zetas as integer),@nuo,@iki,CONVERT (date, @kada),cast(@gryni as float),cast(@bankas as float),cast(@kreditas as float),cast(@technologija as float))


END

GO

